from DataAccess.DBConnFactory import DBConnFactory
from Misc.Utils import *

from string import Template


def query_ls_mkt_exposure(ref_date, portf_id):
	
	sql_tpl = Template('''select * from aggregate_mkt_expo
							where portfolio_id = '${PORT_ID}'
							and ref_date = TO_DATE('${DATE}','yyyy-mm-dd')''')
	
	sql_text = sql_tpl.substitute(DATE = ref_date.isoformat(), 
								  PORT_ID = portf_id)
	
	cursor = DBConnFactory().get_db_connection('PKEDB').cursor()
	cursor.execute(sql_text)
	return cursor.fetchall()